<div class="modal fade" id="withdraw-modal" tabindex="-1" aria-labelledby="withdraw-modal-title" aria-hidden="true" {{ stimulus_controller('pages/part_withdraw_modal') }}>
    <form method="post" action="{{ path('part_add_withdraw', {"id": part.id}) }}">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="withdraw-modal-title"
                        data-withdraw="{% trans %}part.info.withdraw_modal.title.withdraw{% endtrans %}"
                        data-add="{% trans %}part.info.withdraw_modal.title.add{% endtrans %}"
                        data-move="{% trans %}part.info.withdraw_modal.title.move{% endtrans %}"
                    >Filled by JS Controller</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    {# non visible form elements #}
                    <input type="hidden" name="lot_id" value="">
                    <input type="hidden" name="action" value="">
                    <input type="hidden" name="_csfr" value="{{ csrf_token('part_withraw' ~ part.iD) }}">
                    <input type="hidden" name="_redirect" value="{{  uri_without_host(app.request) }}">

                    <div class="row mb-2">
                        <label class="col-form-label col-sm-3">
                            {% trans %}part.info.withdraw_modal.amount{% endtrans %}
                        </label>
                        <div class="col-sm-9">
                            <input type="number" required class="form-control" min="0" step="{{ (part.partUnit and not part.partUnit.integer) ? 'any' : '1' }}" name="amount" value="">
                        </div>
                    </div>

                    <div class="row mb-2 d-none" id="withdraw-modal-move-to">
                        <label class="col-form-label col-sm-3">{% trans %}part.info.withdraw_modal.move_to{% endtrans %}</label>
                        <div class="col-sm-9">
                            {% for lots in part.partLots|filter(l => l.instockUnknown == false) %}

                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="target_id" value="{{ lots.iD }}" id="modal_target_radio_{{ lots.iD }}" {% if not withdraw_add_helper.canAdd(lots) %}disabled{% endif %} required {% if loop.first %}checked{% endif %}>
                                    <label class="form-check-label" for="modal_target_radio_{{ lots.iD }}">
                                        {{ (lots.storageLocation) ? lots.storageLocation.fullPath : ("Lot " ~ loop.index) }}{% if lots.name is not empty %} ({{ lots.name }}){% endif %}: <b>{{ lots.amount | format_amount(part.partUnit) }}</b>
                                    </label>
                                </div>
                            {% endfor %}
                        </div>
                    </div>

                    <div class="row mb-2">
                        <label class="col-form-label col-sm-3">
                            {% trans %}part.info.withdraw_modal.comment{% endtrans %}
                        </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="comment" value="" {% if event_comment_needed('part_stock_operation') %}required{% endif %}>
                            <div id="emailHelp" class="form-text">{% trans %}part.info.withdraw_modal.comment.hint{% endtrans %}</div>
                        </div>
                    </div>

                    <div class="row mb-2">
                        <label class="col-form-label col-sm-3">
                            {% trans %}part.info.withdraw_modal.timestamp{% endtrans %}
                        </label>
                        <div class="col-sm-9">
                            {# The timestamp must be between a year ago and 1 hour in the future #}
                            <input type="datetime-local" class="form-control" name="timestamp" value=""
                                   max="{{ "+10mins"|date('Y-m-d\\TH:i') }}" min="{{ "-1year"|date('Y-m-d\\TH:i') }}">
                            <div id="emailHelp" class="form-text">{% trans %}part.info.withdraw_modal.timestamp.hint{% endtrans %}</div>
                        </div>
                    </div>

                    <div class="row mb-2">
                        <div class="col-sm-9 offset-sm-3">
                            {# The timestamp must be between a year ago and 1 hour in the future #}
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" name="delete_lot_if_empty" value="true" id="withdraw_modal_delete_if_empty">
                                <label class="form-check-label" for="withdraw_modal_delete_if_empty">
                                    {% trans %}part.info.withdraw_modal.delete_lot_if_empty{% endtrans %}
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans %}modal.close{% endtrans %}</button>
                    <button type="submit" class="btn btn-primary">{% trans %}modal.submit{% endtrans %}</button>
                </div>
            </div>
        </div>
    </form>
</div>